package mobil.indkoebsliste;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class list extends Activity {

	Dao dao = Dao.getInstance();

	ArrayList<Vare> listItems = dao.getIndkoebsListe();

	ArrayAdapter<Vare> adapter;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list);

		adapter = new ArrayAdapter<Vare>(this,
				android.R.layout.simple_list_item_1, listItems);
		final ListView lv = (ListView) findViewById(R.id.list_list);
		lv.setAdapter(adapter);

		lv.setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> myAdapter, View myView,
					int myItemInt, long mylng) {
				Vare selectedFromList = (Vare) (lv.getItemAtPosition(myItemInt));
				dao.removeItem(selectedFromList);
			}
		});

	}

	public void onResume() {
		super.onResume();
		listItems = dao.getIndkoebsListe();

		ArrayAdapter<Vare> adapter = new ArrayAdapter<Vare>(this,
				android.R.layout.simple_list_item_1, listItems);
		final ListView lv = (ListView) findViewById(R.id.list_list);
		lv.setAdapter(adapter);
	}

}
